package com.nidu.demo.menu.convertor;

import com.nidu.demo.base.BaseConvertor;
import com.nidu.demo.convertor.MapStructConfig;
import com.nidu.demo.menu.dto.MenuCO;
import com.nidu.demo.menu.dto.MenuTreeCO;
import com.nidu.demo.menu.mapper.dataobject.MenuDO;
import com.nidu.demo.menu.model.Menu;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

import java.util.List;

@Mapper(config = MapStructConfig.class)
public interface MenuConvertor extends BaseConvertor<MenuDO, Menu, MenuCO> {
    
    @Override
    @Mapping(target = "createTime", ignore = true)
    @Mapping(target = "updateTime", ignore = true)
    @Mapping(target = "createBy", ignore = true)
    @Mapping(target = "updateBy", ignore = true)
    @Mapping(source = "menuName", target = "name")
    @Mapping(source = "menuType", target = "type")
    MenuDO toDataObject(Menu menu);

    @Override
    @Mapping(source = "name", target = "menuName")
    @Mapping(source = "type", target = "menuType")
    Menu toDomainObject(MenuDO menuDO);

    List<MenuTreeCO> toTreeClientObjects(List<Menu> menus);
}